# Specify the minimum required CMake version
cmake_minimum_required(VERSION 3.10)

# Project name and language setting
project(file-encryptor C)

# Set C standard to C99 and enforce it
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

# Add compiler warning options for GCC or Clang
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
    add_compile_options(-Wall -Wextra -pedantic)
endif()

# Set include directories (include the project's include folder)
include_directories(${PROJECT_SOURCE_DIR}/include)

# Define source files list
set(SRC_FILES
    src/encrypt.c
    src/decrypt.c
    src/utils.c
)

# Create a library from the source files
add_library(encryptor_lib   ${SRC_FILES})

# Add the main executable target
add_executable(encryptor src/main.c)
target_link_libraries(encryptor PRIVATE encryptor_lib)

# Add the test executable
add_executable(test_encrypt test/test_encrypt.c)
target_link_libraries(test_encrypt PRIVATE encryptor_lib)

# Enable testing and add a test target
enable_testing()
add_test(NAME test_encrypt COMMAND test_encrypt)

# Set output directory for main executable
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

# Set output directory for test executable (optional)
set_target_properties(test_encrypt PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})